/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ept.controller;

import com.ept.entities.Commandeclient;
import com.ept.entities.Utilisateur;
import com.ept.facade.UtilisateurFacade;
import java.io.Serializable;
import java.util.Calendar;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
import org.primefaces.extensions.event.timeline.TimelineSelectEvent;
import org.primefaces.extensions.model.timeline.TimelineEvent;
import org.primefaces.extensions.model.timeline.TimelineModel;

/**
 *
 * @author Khalil
 */
@ManagedBean(name = "basicTimelineController") 
@ViewScoped  
public class BasicTimelineController implements Serializable, ActionListener {  
    private Utilisateur utilisateur;
    @EJB
    private UtilisateurFacade utilisateurfacade;
    List<Commandeclient> list;
    @EJB
    private com.ept.facade.CommandeclientFacade commandeclientFacade;
    
    private TimelineModel model;  
    private boolean selectable = true;  
    private boolean zoomable = true;  
    private boolean moveable = true;  
    private boolean stackEvents = true;  
    private String eventStyle = "box";  
    private boolean axisOnTop;  
    private boolean showCurrentTime = true;  
    private boolean showNavigation = false;  
  
    @PostConstruct  
    protected void initialize() {  
        model = new TimelineModel();  
    utilisateur= utilisateurfacade.findByUserName("khalil");
    list = commandeclientFacade.findAchat(utilisateur.getPanier());
    Calendar cal = Calendar.getInstance(); 
    for (Commandeclient current : list) {
        System.out.println(current.getDate());
        
            model.add(new TimelineEvent(current.getIdProduit().getNomProduit(),current.getDate()));;
        }
         
//        cal.set(2011, Calendar.MAY, 10, 0, 0, 0);  
//          
//  
//        cal.set(2012, Calendar.JANUARY, 23, 0, 0, 0);  
//        model.add(new TimelineEvent("Primefaces-Extensions 0.2.0", cal.getTime()));  
//  
//        cal.set(2012, Calendar.APRIL, 2, 0, 0, 0);  
//        model.add(new TimelineEvent("Primefaces-Extensions 0.3.0", cal.getTime()));  
//  
//        cal.set(2012, Calendar.APRIL, 16, 0, 0, 0);  
//        model.add(new TimelineEvent("Primefaces-Extensions 0.4.0", cal.getTime()));  
//  
//        cal.set(2012, Calendar.JUNE, 10, 0, 0, 0);  
//        model.add(new TimelineEvent("Primefaces-Extensions 0.5.0", cal.getTime()));  
//  
//        cal.set(2012, Calendar.JUNE, 19, 0, 0, 0);  
//        model.add(new TimelineEvent("Primefaces-Extensions 0.5.1", cal.getTime()));  
//  
//        cal.set(2012, Calendar.SEPTEMBER, 26, 0, 0, 0);  
//        model.add(new TimelineEvent("Primefaces-Extensions 0.6.0", cal.getTime()));  
//  
//        cal.set(2012, Calendar.OCTOBER, 13, 0, 0, 0);  
//        model.add(new TimelineEvent("Primefaces-Extensions 0.6.1", cal.getTime()));  
//  
//        cal.set(2012, Calendar.DECEMBER, 16, 0, 0, 0);  
//        model.add(new TimelineEvent("Primefaces-Extensions 0.6.2", cal.getTime()));  
//  
//        cal.set(2013, Calendar.FEBRUARY, 3, 0, 0, 0);  
//        model.add(new TimelineEvent("Primefaces-Extensions 0.6.3", cal.getTime()));  
    }  
  
    public void onSelect(TimelineSelectEvent e) {  
        TimelineEvent timelineEvent = e.getTimelineEvent();  
  
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Selected event:", timelineEvent.getData().toString());  
        FacesContext.getCurrentInstance().addMessage(null, msg);  
    }  
  
    public TimelineModel getModel() {  
        return model;  
    }  
  
    public boolean isSelectable() {  
        return selectable;  
    }  
  
    public void setSelectable(boolean selectable) {  
        this.selectable = selectable;  
    }  
  
    public boolean isZoomable() {  
        return zoomable;  
    }  
  
    public void setZoomable(boolean zoomable) {  
        this.zoomable = zoomable;  
    }  
  
    public boolean isMoveable() {  
        return moveable;  
    }  
  
    public void setMoveable(boolean moveable) {  
        this.moveable = moveable;  
    }  
  
    public boolean isStackEvents() {  
        return stackEvents;  
    }  
  
    public void setStackEvents(boolean stackEvents) {  
        this.stackEvents = stackEvents;  
    }  
  
    public String getEventStyle() {  
        return eventStyle;  
    }  
  
    public void setEventStyle(String eventStyle) {  
        this.eventStyle = eventStyle;  
    }  
  
    public boolean isAxisOnTop() {  
        return axisOnTop;  
    }  
  
    public void setAxisOnTop(boolean axisOnTop) {  
        this.axisOnTop = axisOnTop;  
    }  
  
    public boolean isShowCurrentTime() {  
        return showCurrentTime;  
    }  
  
    public void setShowCurrentTime(boolean showCurrentTime) {  
        this.showCurrentTime = showCurrentTime;  
    }  
  
    public boolean isShowNavigation() {  
        return showNavigation;  
    }  
  
    public void setShowNavigation(boolean showNavigation) {  
        this.showNavigation = showNavigation;  
    }  

    @Override
    public void processAction(ActionEvent event) throws AbortProcessingException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}   